home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
vol15n10.zip
/
MULTIL.ZIP
/
MLSRC.ZIP
/
MSDEV
/
PROJECTS
/
MLAUNCH
/
REGISTRY.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-11
|
3KB
|
144 lines
// Registry helper functions
#include "StdAfx.h"
#include "Registry.h"
// Implementation of CRegistryKey
// Default constructor
CRegistryKey::CRegistryKey()
{
}
// Go through the linked list and destroy all CRegistryValue objects found
CRegistryKey::~CRegistryKey()
{
POSITION pos;
for( pos = m_RegistryValues.GetHeadPosition(); pos != NULL; )
delete (CRegistryValue*) m_RegistryValues.GetNext(pos);
}
// Initialize object with a new key
CRegistryKey::CRegistryKey(CString strRegistryKey)
{
ASSERT(strRegistryKey != "");
int i = 0;
HKEY hKey;
long lResult;
CString strName, strValue;
CRegistryValue* RegistryValue;
DWORD dwlenName, dwlenValue, dwType;
m_strRegistryKey = strRegistryKey;
// Open the desired key
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, strRegistryKey, 0, KEY_ALL_ACCESS, &hKey)
== ERROR_SUCCESS) {
// Enumerate the values under MultiLaunch key
dwlenName = 100;
dwlenValue = 100;
lResult = RegEnumValue(hKey, i++, strName.GetBuffer(dwlenName), &dwlenName,
0, &dwType, (BYTE*) strValue.GetBuffer(dwlenValue), &dwlenValue);
while (lResult != ERROR_NO_MORE_ITEMS) {
strName.ReleaseBuffer();
strValue.ReleaseBuffer();
// Add to my linked list
RegistryValue = new CRegistryValue(strName, strValue);
m_RegistryValues.AddTail((CObject*) RegistryValue);
dwlenName = 100;
dwlenValue = 100;
lResult = RegEnumValue(hKey, i++, strName.GetBuffer(dwlenName), &dwlenName,
0, &dwType, (BYTE*) strValue.GetBuffer(dwlenValue), &dwlenValue);
}
strName.ReleaseBuffer();
strValue.ReleaseBuffer();
RegistryValue = new CRegistryValue(strName, strValue);
m_RegistryValues.AddTail((CObject*) RegistryValue);
// Initialize the list
GotoHead();
}
}
// Goto head of the list
void CRegistryKey::GotoHead()
{
m_pos = m_RegistryValues.GetHeadPosition();
}
// Get next element in the list
BOOL CRegistryKey::GetNext(CRegistryValue*& pRegistryValue)
{
BOOL bResult = TRUE;
if (m_RegistryValues.GetCount() > 0)
pRegistryValue = (CRegistryValue*) m_RegistryValues.GetNext(m_pos);
else
return FALSE;
if (m_pos == NULL)
bResult = FALSE;
return bResult;
}
// Get element at a certain offset into the list (0-based)
CRegistryValue* CRegistryKey::GetAt(int iIndex)
{
CRegistryValue* pRegistryValue = NULL;
POSITION pos = m_RegistryValues.FindIndex(iIndex);
if (pos != NULL)
pRegistryValue = (CRegistryValue*) m_RegistryValues.GetAt(pos);
return pRegistryValue;
}
// Remove element at a certain offset into the list (0-based)
void CRegistryKey::RemoveAt(int iIndex)
{
POSITION pos = m_RegistryValues.FindIndex(iIndex);
if (pos != NULL)
m_RegistryValues.RemoveAt(pos);
}
// Get count of the number of items in the list
int CRegistryKey::GetCount()
{
return m_RegistryValues.GetCount();
}
// Implementation of CRegistryValue
// Default constructor
CRegistryValue::CRegistryValue()
{
}
// Default destructor
CRegistryValue::~CRegistryValue()
{
}
// Initialize object with a new registry value
CRegistryValue::CRegistryValue(CString strName, CString strValue)
{
m_strName = strName;
m_strValue = strValue;
}